In [4]:
import pandas as pd
In [5]:
from pycoingecko import CoinGeckoAPI
In [6]:
cga = CoinGeckoAPI()
In [28]:
#Assigning the bitcoin data of 90 days in USD 
bitcoin_data = cga.get_coin_market_chart_by_id(
    id='bitcoin',
    vs_currency='usd',
    days=90
)
    
In [29]:
#Assigning the ethereum data of 90 days in USD 
ethereum_data = cga.get_coin_market_chart_by_id(
    id='ethereum',
    vs_currency='usd',
    days=90
)
In [30]:
#Converting  JSON file to data frame
b_df= pd.DataFrame(
    bitcoin_data['prices'],
    columns=['Timestamp','Prices']
                  )
In [11]:
b_df.head()
Out[11]:
Timestamp Prices
0 1735805028685 95718.778413
1 1735808626305 96000.772732
2 1735812235758 96427.253640
3 1735815838397 96481.025485
4 1735819438190 96653.952201
In [31]:
#Converting  JSON file to data frame
e_df= pd.DataFrame(
    ethereum_data['prices'],
    columns=['Timestamp','Prices']
                  )
In [13]:
e_df.head()
Out[13]:
Timestamp Prices
0 1735805025840 3415.831829
1 1735808624336 3432.312658
2 1735812233796 3446.195773
3 1735815835214 3462.735037
4 1735819434942 3468.975545
In [32]:
# Converting Time stamps to Date 
b_df['Date']=pd.to_datetime(b_df['Timestamp'], unit = 'ms')
In [33]:
# Converting Time stamps to Date
e_df['Date']=pd.to_datetime(e_df['Timestamp'], unit = 'ms')
In [16]:
b_df.head()
Out[16]:
Timestamp Prices Date
0 1735805028685 95718.778413 2025-01-02 08:03:48.685
1 1735808626305 96000.772732 2025-01-02 09:03:46.305
2 1735812235758 96427.253640 2025-01-02 10:03:55.758
3 1735815838397 96481.025485 2025-01-02 11:03:58.397
4 1735819438190 96653.952201 2025-01-02 12:03:58.190
In [17]:
e_df.head()
Out[17]:
Timestamp Prices Date
0 1735805025840 3415.831829 2025-01-02 08:03:45.840
1 1735808624336 3432.312658 2025-01-02 09:03:44.336
2 1735812233796 3446.195773 2025-01-02 10:03:53.796
3 1735815835214 3462.735037 2025-01-02 11:03:55.214
4 1735819434942 3468.975545 2025-01-02 12:03:54.942
In [34]:
# Grouping Prices as minimum, maximum, first and Last value of each day
bd_group = b_df.groupby(b_df.Date.dt.date).agg({'Prices':['min', 'max', 'first', 'last']})
In [35]:
# Grouping Prices as minimum, maximum, first and Last value of each day
ed_group = e_df.groupby(e_df.Date.dt.date).agg({'Prices':['min', 'max', 'first', 'last']})
In [20]:
bd_group.head()
Out[20]:
Prices
min max first last
Date
2025-01-02 95718.778413 97433.160066 95718.778413 96839.913680
2025-01-03 96010.075390 98547.435498 96897.897739 98273.148214
2025-01-04 97647.466574 98597.697785 98150.883784 98318.610635
2025-01-05 97597.295638 98674.471779 98210.984491 98674.471779
2025-01-06 98260.455544 102183.669137 98349.761456 102079.847212
In [21]:
ed_group.head()
Out[21]:
Prices
min max first last
Date
2025-01-02 3415.831829 3492.241973 3415.831829 3439.052969
2025-01-03 3425.505902 3617.920696 3451.217443 3615.269761
2025-01-04 3583.109664 3658.600389 3607.371132 3657.115221
2025-01-05 3608.126312 3656.822200 3656.822200 3650.182257
2025-01-06 3622.128722 3714.584702 3635.087446 3682.122032
In [22]:
#import plotly.graph_objects
import plotly.graph_objects as go
In [24]:
#assigning fig
fig = go.Figure( data = [
    go.Candlestick(x=bd_group.index,
                   open = bd_group['Prices']['first'],
                   high = bd_group['Prices']['max'],
                   low = bd_group['Prices']['min'],
                   close = bd_group['Prices']['last']
                  )
])
In [25]:
fig.update_layout(xaxis_rangeslider_visible = False, xaxis_title = 'Date',
                 yaxis_title='Prices (USD $)', title = 'Bitcoin Candle stick Chart over past 90 Days'
                 )
In [26]:
#assigning fig2
fig2 = go.Figure( data = [
    go.Candlestick(x=ed_group.index,
                   open = ed_group['Prices']['first'],
                   high = ed_group['Prices']['max'],
                   low = ed_group['Prices']['min'],
                   close = ed_group['Prices']['last']
                  )
])
In [27]:
fig2.update_layout(xaxis_rangeslider_visible = False, xaxis_title = 'Date',
                 yaxis_title='Prices (USD $)', title = 'Ethereum Candle stick Chart over past 90 Days'
                 )
In [ ]:
 
In [ ]: